package com.mit.service.purchase.dao.impl;

import java.util.HashMap;
import java.util.List;

import com.mit.common.exception.NoRecordUpdateException;
import com.mit.common.purchase.dto.InquiryTaskDTO;
import com.mit.service.core.dao.AbstractDAO;
import com.mit.service.purchase.dao.IInquiryTaskDAO;

public class InquiryTaskDAOImpl extends AbstractDAO implements IInquiryTaskDAO {

	@Override
	public InquiryTaskDTO createInquiryTaskDTO(InquiryTaskDTO to) {
		Integer id = (Integer) getSqlMapClientTemplate().insert("insertInquiryTask", to);
		to.setId(id);
		return to;
	}

	@Override
	public Integer retrieveTaskIdByStyleId(Integer styleId) {
		
		return (Integer) getSqlMapClientTemplate().queryForObject("selectInquiryTaskIdByStyle", styleId);
	}

	@Override
	public void updateInquiryTaskState(Integer taskId) throws NoRecordUpdateException{

		int row = getSqlMapClientTemplate().update("updateInquiryTaskState", taskId);
		if(row < 1)
			throw new NoRecordUpdateException();
		
	}

	@Override
	public List<InquiryTaskDTO> retrievePagedInquiryTasks(Integer orgId,
			String styleCode, String state, Integer pageNo, Integer pageSize) {
		InquiryTaskDTO to = new InquiryTaskDTO();
		to.setOrgId(orgId);
		to.getStyle().setCode(styleCode);
		to.setState(state);
		to.setPageNo(pageNo);
		to.setPageSize(pageSize);
		return getSqlMapClientTemplate().queryForList("selectedPagedTasks", to);
	}

	@Override
	public Integer retrieveInquiryTaskCount(Integer orgId, String styleCode,
			String state) {
		InquiryTaskDTO to = new InquiryTaskDTO();
		to.setOrgId(orgId);
		to.getStyle().setCode(styleCode);
		to.setState(state);
		return (Integer) getSqlMapClientTemplate().queryForObject("selectTasksCount", to);
	}

	@Override
	public void updateInquiryTask(InquiryTaskDTO to) throws NoRecordUpdateException{
		int row = getSqlMapClientTemplate().update("updateInquiryTask", to);
		if(row < 1)
			throw new NoRecordUpdateException();
		
	}
	


}
